package action.common;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import dao.common.ManagerDao;
import model.common.Manager;

public class ManagerAction {

	private Manager manager;

	public void add(Manager manager) throws Exception{
		ManagerDao dao=new ManagerDao();
		dao.addManager(manager);
	}
	
	public void get(Integer managerId) throws Exception{
		ManagerDao dao=new ManagerDao();
		dao.get(managerId);
	}
	
	public void edit(Manager manager) throws SQLException{
		ManagerDao dao=new ManagerDao();
		dao.updateManager(manager);
	}
	
	public void del(Integer managerId) throws SQLException{
		ManagerDao dao=new ManagerDao();
		dao.deleteManager(managerId);
	}
	
	public List<Manager> query(List<Map<String, Object>> params) throws Exception{
		ManagerDao dao=new ManagerDao();
		
		return dao.query(params);
		
	}
	
	public List<Manager> query(String managerName,String managerPassword) throws Exception{
		ManagerDao dao=new ManagerDao();
		return dao.query(managerName, managerPassword);
		
	}
	
	public Boolean login(Manager m){
		ManagerDao dao=new ManagerDao();
		Manager m1=dao.getLoginManagerName(m.getManagerName());

		if (m1 != null) {
			if ((m1.getManagerPassword()).equals(m.getManagerPassword())) {
				m.setManagerId(m1.getManagerId());
				m.setManagerAge(m1.getManagerAge());
				m.setManagerSex(m1.getManagerSex());
				m.setManagerEmail(m1.getManagerEmail());
				m.setManagerAddress(m1.getManagerAddress());
				m.setManagerIdentifyId(m1.getManagerIdentifyId());
				m.setManagerTelephone(m1.getManagerTelephone());
				return true;
			}
			else
				return false;
		} else
			return false;
	}
	
}
